package com.zxbg.controller.systemtoolsController;

import com.zxbg.controller.Code;
import com.zxbg.controller.Result;
import com.zxbg.domain.InfoBlockType;
import com.zxbg.service.systemtoolsService.InfoBlockTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/InfoBlockType")
public class InfoBlockTypeController {
    @Autowired
    InfoBlockTypeService infoBlockTypeService;

    @GetMapping("/{belong_block_id}")
    public Result getBlockTypeByBlockId(@PathVariable String belong_block_id, @RequestHeader Integer tenant_id) {
        return new Result(Code.GET_OK, infoBlockTypeService.getBlockTypeByBlockId(belong_block_id, tenant_id));
    }

    @PutMapping
    public Result updateBlockType(@RequestBody Map<String, Object> map, @RequestHeader Integer tenant_id) {
        List<InfoBlockType> infoBlockTypeList = (List<InfoBlockType>) map.get("InfoBlockType");
        String belong_block_id = (String) map.get("belong_block_id");
        boolean flag = infoBlockTypeService.updateBlockType(infoBlockTypeList, belong_block_id, tenant_id);
        return new Result(flag ? Code.UPDATE_OK : Code.UPDATE_ERR, flag);
    }
}
